﻿/*
 *GreyBox was written by Strategic Data Systems and licenced under the open source MS-PL. 
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;

namespace StrategicDataSystems.Cloud.Monitoring.UI.Services
{
    public class InternetPresenceService : INetPresenceService
    {
        [DllImport("wininet.dll", SetLastError = true)]
        extern static bool InternetGetConnectedState(out int lpdwFlags, int dwReserved);

        public bool InternetConnectionIsAvailable()
        {
            int flags;
            bool isConnected = InternetGetConnectedState(out flags, 0);
            Trace.WriteLineIf(!isConnected, "GreyBox did not detect an internet connection.", "System");
            return isConnected;
        }
    }
}
